<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            position: relative;
            margin: 50px auto;
            width: 512px;
            height: 400px;
            overflow: hidden;
        }
        .box img{
            position: absolute;
            top: 0;
            left: 0;
        }
        .box span{
            width: 512px;
            height: 200px;
            position: absolute;
            left: 0;
            /* 光标小手 */
            cursor: pointer;
        }
        .box>span#up{
            top: 0;
        }
        .box>span#down{
            bottom: 0;
        }
    </style>
    <script>
        window.onload = function(){
            function $(selecter){
                return document.querySelector(selecter)
            }
            /* 移动距离 */
            var movelave = 0;
            /* 声明定时器 */
            var timer = null;
            /* 光标在上半部上滑 */
            $("#up").onmouseover = function(){
                /* 率先清除定时器 */
                clearInterval(timer)
                timer = setInterval(() => {
                    movelave -= 3;
                    if(movelave<=-1070){
                        clearInterval(timer)
                    }else{
                        $('img').style.top=movelave+'px';
                    }
                }, 30);
            }
            /* 下滑 */
            $("#down").onmouseover = function(){
                /* 率先清除定时器 */
                clearInterval(timer)
                timer = setInterval(() => {
                    movelave += 3;
                    if(movelave<=0){
                        $('img').style.top=movelave+'px';
                    }else{
                        clearInterval(timer)
                    }
                }, 30);
            }
            /* 移出停止 */
            $('.box').onmouseout=function(){
                clearInterval(timer)
            }
        }
    </script>
</head>
<body>
    <div class="box">
        <img src="./image/mi.png" alt="">
        <!-- 辅助元素 -->
        <span id="up"></span>
        <span id="down"></span>
    </div>
</body>
</html>